/*
 * Created by JFormDesigner on Sun Jun 26 16:50:56 CST 2022
 */

package com.keshe.jsp;

import com.keshe.service.RoomContorller;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.GroupLayout;
import javax.swing.table.*;

/**
 * @author 1
 */
public class SelectRoom extends JFrame {
    public SelectRoom() {
        initComponents();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");
        panel1 = new JPanel();
        scrollPane1 = new JScrollPane();
        table1 = new JTable();
        textField1 = new JTextField();
        label1 = new JLabel();
        button5 = new JButton();
        button6 = new JButton();
        button1 = new JButton();
        radioButton1 = new JRadioButton();
        radioButton2 = new JRadioButton();
        action1 = new Return();
        action2 = new select();
        action3 = new shuaxin();

        //======== this ========
        setIconImage(new ImageIcon(getClass().getResource("/images/\u9152\u5e97 (1).png")).getImage());
        setTitle("\u67e5\u8be2\u5ba2\u623f");
        Container contentPane = getContentPane();

        //======== panel1 ========
        {

            //======== scrollPane1 ========
            {

                //---- table1 ----
                table1.setModel(new DefaultTableModel(
                    new Object[][] {
                        {null, null, null, null, null, null, null, ""},
                        {null, null, null, null, null, null, null, null},
                    },
                    new String[] {
                        "\u5ba2\u623f\u7f16\u53f7", "\u5ba2\u623f\u7c7b\u578b", "\u4f4d\u7f6e", "\u4ef7\u683c", "\u623f\u95f4\u9762\u79ef", "\u662f\u5426\u7a7a\u95f2", "\u6e05\u6d01\u72b6\u51b5", "\u63cf\u8ff0"
                    }
                ));
                table1.setSurrendersFocusOnKeystroke(true);
                table1.setAutoCreateRowSorter(true);
                scrollPane1.setViewportView(table1);
            }

            //---- label1 ----
            label1.setText(bundle.getString("label1.text_12"));
            label1.setIcon(new ImageIcon(getClass().getResource("/images/\u767e\u671b\u4e91-\u884c\u4e1a-\u9152\u5e97s (2).png")));
            label1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));

            //---- button5 ----
            button5.setAction(action3);

            //---- button6 ----
            button6.setAction(action1);

            //---- button1 ----
            button1.setAction(action2);
            button1.setText(bundle.getString("button1.text_4"));
            button1.setIcon(new ImageIcon(getClass().getResource("/images/\u641c\u7d22.png")));

            //---- radioButton1 ----
            radioButton1.setText(bundle.getString("radioButton1.text"));

            //---- radioButton2 ----
            radioButton2.setText(bundle.getString("radioButton2.text_3"));

            GroupLayout panel1Layout = new GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panel1Layout.createParallelGroup()
                            .addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                                .addComponent(label1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(panel1Layout.createParallelGroup()
                                    .addGroup(panel1Layout.createSequentialGroup()
                                        .addGap(650, 650, 650)
                                        .addComponent(button5, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(48, 48, 48)
                                        .addComponent(button6)
                                        .addGap(34, 34, 34))
                                    .addGroup(panel1Layout.createSequentialGroup()
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(radioButton2)
                                        .addGap(18, 18, 18)
                                        .addComponent(radioButton1)
                                        .addGap(29, 29, 29)
                                        .addComponent(textField1, GroupLayout.PREFERRED_SIZE, 350, GroupLayout.PREFERRED_SIZE)
                                        .addGap(41, 41, 41)
                                        .addComponent(button1)
                                        .addGap(73, 73, 73))))
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addComponent(scrollPane1)
                                .addContainerGap())))
            );
            panel1Layout.setVerticalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label1, GroupLayout.PREFERRED_SIZE, 132, GroupLayout.PREFERRED_SIZE)
                            .addComponent(textField1)
                            .addComponent(radioButton1)
                            .addComponent(radioButton2)
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(button1)))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 408, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(button5)
                            .addComponent(button6))
                        .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
        }

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addComponent(panel1, GroupLayout.PREFERRED_SIZE, 598, GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 5, Short.MAX_VALUE))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel panel1;
    private JScrollPane scrollPane1;
    private JTable table1;
    private JTextField textField1;
    private JLabel label1;
    private JButton button5;
    private JButton button6;
    private JButton button1;
    private JRadioButton radioButton1;
    private JRadioButton radioButton2;
    private Return action1;
    private select action2;
    private shuaxin action3;
    // JFormDesigner - End of variables declaration  //GEN-END:variables

    private class Return extends AbstractAction {
        private Return() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action1.Name_13"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            dispose();
            new Index().setVisible(true);
        }
    }

    private class select extends AbstractAction {
        private select() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action2.Name_7"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            if(radioButton1.isSelected()==true&&radioButton2.isSelected()==true){
                JOptionPane.showMessageDialog(null,"只能选择一种查询方式哦！");
            }else if(radioButton1.isSelected()==false&&radioButton2.isSelected()==false){
                JOptionPane.showMessageDialog(null,"至少选择一种查询方式哦！");
            }else if(radioButton2.isSelected()==true){
                RoomContorller rc=new RoomContorller();
                if(rc.selectId(textField1.getText()).length==0){
                    JOptionPane.showMessageDialog(null,"没有找到该数据，请重新输入！");
                }else{
                    table1.setModel(new DefaultTableModel(
                            rc.selectId(textField1.getText()),
                            new String[] {
                                    "\u5ba2\u623f\u7f16\u53f7", "\u5ba2\u623f\u7c7b\u578b", "\u4f4d\u7f6e", "\u4ef7\u683c", "\u623f\u95f4\u9762\u79ef", "\u662f\u5426\u7a7a\u95f2", "\u6e05\u6d01\u72b6\u51b5", "\u63cf\u8ff0"
                            }
                    ));
                }
            }else{
                RoomContorller rc=new RoomContorller();
                if(rc.selectName(textField1.getText()).length==0){
                    JOptionPane.showMessageDialog(null,"没有找到该数据，请重新输入！");
                }else{
                    table1.setModel(new DefaultTableModel(
                            rc.selectName(textField1.getText()),
                            new String[] {
                                    "\u5ba2\u623f\u7f16\u53f7", "\u5ba2\u623f\u7c7b\u578b", "\u4f4d\u7f6e", "\u4ef7\u683c", "\u623f\u95f4\u9762\u79ef", "\u662f\u5426\u7a7a\u95f2", "\u6e05\u6d01\u72b6\u51b5", "\u63cf\u8ff0"
                            }
                    ));
                }
            }
        }
    }

    private class shuaxin extends AbstractAction {
        private shuaxin() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action3.Name_2"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            RoomContorller rc=new RoomContorller();
            table1.setModel(new DefaultTableModel(
                    rc.showALL(),
                    new String[] {
                            "\u5ba2\u623f\u7f16\u53f7", "\u5ba2\u623f\u7c7b\u578b", "\u4f4d\u7f6e", "\u4ef7\u683c", "\u623f\u95f4\u9762\u79ef", "\u662f\u5426\u7a7a\u95f2", "\u6e05\u6d01\u72b6\u51b5", "\u63cf\u8ff0"
                    }
            ));
        }
    }
}
